package com.abc.robot01.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.abc.robot01.Base64QrCodeImage
import com.abc.robot01.R
import com.abc.robot01.activity.MYBLACK
import com.abc.robot01.activity.MYBLACK_Percent60
import com.abc.robot01.activity.MyFont_Size
import com.abc.robot01.activity.SystemFragmentBackground
import com.abc.robot01.activity.mysp
import com.abc.robot01.activity.px
import com.abc.robot01.databinding.Fragment03Binding
import com.abc.robot01.vivemodel.Robot
import com.abc.robot01.vivemodel.RobotInfoViewModel
import com.abc.robot01.vivemodel.RobotInfoViewModel7
import com.abc.robot01.vivemodel.ZhifuViewModel

/**
 * A simple [Fragment] subclass as the default destination in the navigation.
 */
class RobotInfoFragment7 : Fragment() {

    private val viewModel: RobotInfoViewModel7 by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel.load()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val composeView = ComposeView(requireContext()).apply {
            setContent {
                SystemFragmentBackground {
                    Column(
                        modifier = Modifier.fillMaxSize(),
                        verticalArrangement = Arrangement.Center,
                        horizontalAlignment = Alignment.CenterHorizontally
                    ) {

                        Base64QrCodeImage(viewModel.base64)
                        Spacer(modifier = Modifier.height(33.px))
                        BasicText(
                            text = """
                      请使用"E代名匠"小程序,扫一扫
                  """.trimIndent(),
                            style = TextStyle(
//                          fontWeight = FontWeight.Bold,
                                fontSize = MyFont_Size,
                                color = MYBLACK_Percent60
                            ),
                            )
                        Spacer(modifier = Modifier.height(30.px))
                        BasicText(
                            text = "本机SN码为${Robot.sn}",
                            style = TextStyle(
                                fontSize = 30.mysp,
                                color = MYBLACK
                            ),
                        )
                        Text(text = "")
                    }
                }
            }
        }
        return  composeView
    }
}
